import 'package:casdon/common/utils/string_externtion.dart';
import 'package:casdon/modules/recipe/data/api/recipe_cloud_list_api.dart';
import 'package:casdon/modules/recipe/ui/widgets/Recipe_card_item.dart';

class RecipeCloudModel extends RecipeCardData {
  @override
  int get sort => 0;
  final String id;
  final String name;
  final bool isControl;
  final String mainImg;
  final String view;

  RecipeCloudModel({
    required this.id,
    required this.name,
    required this.isControl,
    required this.mainImg,
    required this.view,
  });

  @override
  bool get isSmart => isControl;
  @override
  String? get url => null;
  @override
  String get recipeId => id;

  @override
  String get imgUrl => mainImg.cropParams700;

  @override
  String get viewCount => view;

  @override
  String get title => name;

  @override
  String get count => "0";

  @override
  RecipeCardData placeholder() {
    throw UnimplementedError();
  }

  // 静态方法转换
  static RecipeCloudModel fromApi(RecipeCloud response) {
    return RecipeCloudModel(
      mainImg: response.imageUrl ?? "",
      name: response.name ?? "",
      isControl: (response.isControl == 1) ? true : false,
      view: response.view ?? "",
      id: response.id ?? "",
    );
  }

  // 批量转换的静态方法
  static List<RecipeCloudModel> listFromApi(List<RecipeCloud> items) {
    return items.map(fromApi).toList();
  }
}
